package com.lill.common.system.exception;

import org.apache.shiro.authz.UnauthorizedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import com.lill.common.system.util.R;

@RestControllerAdvice
public class LillException {

	protected Logger logger = LoggerFactory.getLogger(getClass());
	
	@ExceptionHandler(value = Exception.class)
	public R errorHandler(Exception ex) {
		logger.error(ex.getMessage(), ex);
//		return R.error(500, ex.getMessage());
		return R.error(500, "请按流程操作，无权限");
	}
	@ExceptionHandler(value = StoreConfigException.class)
	public R errorHandlerStoreConfig(StoreConfigException e){
		return R.error(500,e.getMessage());
	}

	@ExceptionHandler(value = UnauthorizedException.class)
	public R errorHandlerUnauthorized(Exception ex) {
		logger.error(ex.getMessage(), ex);
		return R.error(403, "请按流程操作，无权限");
	}
	
	@ExceptionHandler(value = TokenException.class)
	public R errorHandlerTokenOnce(Exception ex) {
		logger.error(ex.getMessage(), ex);
		return R.error(-1, "请重新登录！");
	}
	
	@ExceptionHandler(value = NoRepeatException.class)
	public R errorHandlerNoRepeat(Exception ex) {
		logger.error(ex.getMessage(), ex);
		return R.error(-1, ex.getMessage());
	}
}
